<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Class template scoped_ptr</title>
<link rel="stylesheet" href="../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
<link rel="home" href="../../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
<link rel="up" href="../../boost_interprocess_reference.html#header.boost.interprocess.smart_ptr.scoped_ptr_hpp" title="Header &lt;boost/interprocess/smart_ptr/scoped_ptr.hpp&gt;">
<link rel="prev" href="to_raw_pointer_idp56801600.html" title="Function template to_raw_pointer">
<link rel="next" href="swap_idp56820848.html" title="Function template swap">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../boost.png"></td>
<td align="center"><a href="../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="to_raw_pointer_idp56801600.html"><img src="../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../boost_interprocess_reference.html#header.boost.interprocess.smart_ptr.scoped_ptr_hpp"><img src="../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="swap_idp56820848.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="refentry">
<a name="boost.interprocess.scoped_ptr"></a><div class="titlepage"></div>
<div class="refnamediv">
<h2><span class="refentrytitle">Class template scoped_ptr</span></h2>
<p>boost::interprocess::scoped_ptr</p>
</div>
<h2 xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv-title">Synopsis</h2>
<div xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv"><pre class="synopsis"><span class="comment">// In header: &lt;<a class="link" href="../../boost_interprocess_reference.html#header.boost.interprocess.smart_ptr.scoped_ptr_hpp" title="Header &lt;boost/interprocess/smart_ptr/scoped_ptr.hpp&gt;">boost/interprocess/smart_ptr/scoped_ptr.hpp</a>&gt;

</span><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> T<span class="special">,</span> <span class="keyword">typename</span> Deleter<span class="special">&gt;</span> 
<span class="keyword">class</span> <a class="link" href="scoped_ptr.html" title="Class template scoped_ptr">scoped_ptr</a> <span class="special">{</span>
<span class="keyword">public</span><span class="special">:</span>
  <span class="comment">// types</span>
  <span class="keyword">typedef</span> <span class="identifier">T</span>                    <a name="boost.interprocess.scoped_ptr.element_type"></a><span class="identifier">element_type</span><span class="special">;</span>         
  <span class="keyword">typedef</span> <span class="identifier">Deleter</span>              <a name="boost.interprocess.scoped_ptr.deleter_type"></a><span class="identifier">deleter_type</span><span class="special">;</span>         
  <span class="keyword">typedef</span> <span class="emphasis"><em><span class="identifier">unspecified</span></em></span>          <a name="boost.interprocess.scoped_ptr.pointer"></a><span class="identifier">pointer</span><span class="special">;</span>              
  <span class="keyword">typedef</span> <span class="identifier">pointer</span> <span class="identifier">this_type</span><span class="special">::</span><span class="special">*</span> <a name="boost.interprocess.scoped_ptr.unspecified_bool_type"></a><span class="identifier">unspecified_bool_type</span><span class="special">;</span>

  <span class="comment">// <a class="link" href="scoped_ptr.html#boost.interprocess.scoped_ptrconstruct-copy-destruct">construct/copy/destruct</a></span>
  <span class="keyword">explicit</span> <a class="link" href="scoped_ptr.html#idp56818656-bb"><span class="identifier">scoped_ptr</span></a><span class="special">(</span><span class="keyword">const</span> <span class="identifier">pointer</span> <span class="special">&amp;</span> <span class="special">=</span> <span class="number">0</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">Deleter</span> <span class="special">&amp;</span> <span class="special">=</span> <span class="identifier">Deleter</span><span class="special">(</span><span class="special">)</span><span class="special">)</span><span class="special">;</span>
  <a class="link" href="scoped_ptr.html#idp56820432-bb"><span class="special">~</span><span class="identifier">scoped_ptr</span></a><span class="special">(</span><span class="special">)</span><span class="special">;</span>

  <span class="comment">// <a class="link" href="scoped_ptr.html#idp56808384-bb">public member functions</a></span>
  <span class="keyword">void</span> <a class="link" href="scoped_ptr.html#idp56808592-bb"><span class="identifier">reset</span></a><span class="special">(</span><span class="keyword">const</span> <span class="identifier">pointer</span> <span class="special">&amp;</span> <span class="special">=</span> <span class="number">0</span><span class="special">)</span><span class="special">;</span>
  <span class="keyword">void</span> <a class="link" href="scoped_ptr.html#idp56809824-bb"><span class="identifier">reset</span></a><span class="special">(</span><span class="keyword">const</span> <span class="identifier">pointer</span> <span class="special">&amp;</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">Deleter</span> <span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
  <span class="identifier">pointer</span> <a class="link" href="scoped_ptr.html#idp56811264-bb"><span class="identifier">release</span></a><span class="special">(</span><span class="special">)</span><span class="special">;</span>
  <span class="identifier">reference</span> <a class="link" href="scoped_ptr.html#idp56812032-bb"><span class="keyword">operator</span><span class="special">*</span></a><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
  <span class="identifier">pointer</span> <span class="special">&amp;</span> <a class="link" href="scoped_ptr.html#idp56812784-bb"><span class="keyword">operator</span><span class="special">-&gt;</span></a><span class="special">(</span><span class="special">)</span><span class="special">;</span>
  <span class="keyword">const</span> <span class="identifier">pointer</span> <span class="special">&amp;</span> <a class="link" href="scoped_ptr.html#idp56813504-bb"><span class="keyword">operator</span><span class="special">-&gt;</span></a><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
  <span class="identifier">pointer</span> <span class="special">&amp;</span> <a class="link" href="scoped_ptr.html#idp56814224-bb"><span class="identifier">get</span></a><span class="special">(</span><span class="special">)</span><span class="special">;</span>
  <span class="keyword">const</span> <span class="identifier">pointer</span> <span class="special">&amp;</span> <a class="link" href="scoped_ptr.html#idp56814928-bb"><span class="identifier">get</span></a><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
  <a class="link" href="scoped_ptr.html#idp56815632-bb"><span class="keyword">operator</span> <span class="identifier">unspecified_bool_type</span></a><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
  <span class="keyword">bool</span> <a class="link" href="scoped_ptr.html#idp56816368-bb"><span class="keyword">operator</span><span class="special">!</span></a><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
  <span class="keyword">void</span> <a class="link" href="scoped_ptr.html#idp56817088-bb"><span class="identifier">swap</span></a><span class="special">(</span><a class="link" href="scoped_ptr.html" title="Class template scoped_ptr">scoped_ptr</a> <span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
<span class="special">}</span><span class="special">;</span></pre></div>
<div class="refsect1">
<a name="idp77421568"></a><h2>Description</h2>
<p><a class="link" href="scoped_ptr.html" title="Class template scoped_ptr">scoped_ptr</a> stores a pointer to a dynamically allocated object. The object pointed to is guaranteed to be deleted, either on destruction of the <a class="link" href="scoped_ptr.html" title="Class template scoped_ptr">scoped_ptr</a>, or via an explicit reset. The user can avoid this deletion using release(). <a class="link" href="scoped_ptr.html" title="Class template scoped_ptr">scoped_ptr</a> is parameterized on T (the type of the object pointed to) and Deleter (the functor to be executed to delete the internal pointer). The internal pointer will be of the same pointer type as typename Deleter::pointer type (that is, if typename Deleter::pointer is offset_ptr&lt;void&gt;, the internal pointer will be offset_ptr&lt;T&gt;). </p>
<div class="refsect2">
<a name="idp77423360"></a><h3>
<a name="boost.interprocess.scoped_ptrconstruct-copy-destruct"></a><code class="computeroutput">scoped_ptr</code> 
        public
       construct/copy/destruct</h3>
<div class="orderedlist"><ol class="orderedlist" type="1">
<li class="listitem">
<pre class="literallayout"><span class="keyword">explicit</span> <a name="idp56818656-bb"></a><span class="identifier">scoped_ptr</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">pointer</span> <span class="special">&amp;</span> p <span class="special">=</span> <span class="number">0</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">Deleter</span> <span class="special">&amp;</span> d <span class="special">=</span> <span class="identifier">Deleter</span><span class="special">(</span><span class="special">)</span><span class="special">)</span><span class="special">;</span></pre>
<p>Constructs a <code class="computeroutput"><a class="link" href="scoped_ptr.html" title="Class template scoped_ptr">scoped_ptr</a></code>, storing a copy of p(which can be 0) and d. Does not throw. </p>
</li>
<li class="listitem">
<pre class="literallayout"><a name="idp56820432-bb"></a><span class="special">~</span><span class="identifier">scoped_ptr</span><span class="special">(</span><span class="special">)</span><span class="special">;</span></pre>
<p>If the stored pointer is not 0, destroys the object pointed to by the stored pointer. calling the operator() of the stored deleter. Never throws </p>
</li>
</ol></div>
</div>
<div class="refsect2">
<a name="idp77433808"></a><h3>
<a name="idp56808384-bb"></a><code class="computeroutput">scoped_ptr</code> public member functions</h3>
<div class="orderedlist"><ol class="orderedlist" type="1">
<li class="listitem">
<pre class="literallayout"><span class="keyword">void</span> <a name="idp56808592-bb"></a><span class="identifier">reset</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">pointer</span> <span class="special">&amp;</span> p <span class="special">=</span> <span class="number">0</span><span class="special">)</span><span class="special">;</span></pre>
<p>Deletes the object pointed to by the stored pointer and then stores a copy of p. Never throws </p>
</li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">void</span> <a name="idp56809824-bb"></a><span class="identifier">reset</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">pointer</span> <span class="special">&amp;</span> p<span class="special">,</span> <span class="keyword">const</span> <span class="identifier">Deleter</span> <span class="special">&amp;</span> d<span class="special">)</span><span class="special">;</span></pre>
<p>Deletes the object pointed to by the stored pointer and then stores a copy of p and a copy of d. </p>
</li>
<li class="listitem">
<pre class="literallayout"><span class="identifier">pointer</span> <a name="idp56811264-bb"></a><span class="identifier">release</span><span class="special">(</span><span class="special">)</span><span class="special">;</span></pre>
<p>Assigns internal pointer as 0 and returns previous pointer. This will avoid deletion on destructor </p>
</li>
<li class="listitem">
<pre class="literallayout"><span class="identifier">reference</span> <a name="idp56812032-bb"></a><span class="keyword">operator</span><span class="special">*</span><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span></pre>
<p>Returns a reference to the object pointed to by the stored pointer. Never throws. </p>
</li>
<li class="listitem">
<pre class="literallayout"><span class="identifier">pointer</span> <span class="special">&amp;</span> <a name="idp56812784-bb"></a><span class="keyword">operator</span><span class="special">-&gt;</span><span class="special">(</span><span class="special">)</span><span class="special">;</span></pre>
<p>Returns the internal stored pointer. Never throws. </p>
</li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">const</span> <span class="identifier">pointer</span> <span class="special">&amp;</span> <a name="idp56813504-bb"></a><span class="keyword">operator</span><span class="special">-&gt;</span><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span></pre>
<p>Returns the internal stored pointer. Never throws. </p>
</li>
<li class="listitem">
<pre class="literallayout"><span class="identifier">pointer</span> <span class="special">&amp;</span> <a name="idp56814224-bb"></a><span class="identifier">get</span><span class="special">(</span><span class="special">)</span><span class="special">;</span></pre>
<p>Returns the stored pointer. Never throws. </p>
</li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">const</span> <span class="identifier">pointer</span> <span class="special">&amp;</span> <a name="idp56814928-bb"></a><span class="identifier">get</span><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span></pre>
<p>Returns the stored pointer. Never throws. </p>
</li>
<li class="listitem">
<pre class="literallayout"><a name="idp56815632-bb"></a><span class="keyword">operator</span> <span class="identifier">unspecified_bool_type</span><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span></pre>
<p>Conversion to bool Never throws </p>
</li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">bool</span> <a name="idp56816368-bb"></a><span class="keyword">operator</span><span class="special">!</span><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span></pre>
<p>Returns true if the stored pointer is 0. Never throws. </p>
</li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">void</span> <a name="idp56817088-bb"></a><span class="identifier">swap</span><span class="special">(</span><a class="link" href="scoped_ptr.html" title="Class template scoped_ptr">scoped_ptr</a> <span class="special">&amp;</span> b<span class="special">)</span><span class="special">;</span></pre>
<p>Exchanges the internal pointer and deleter with other <code class="computeroutput"><a class="link" href="scoped_ptr.html" title="Class template scoped_ptr">scoped_ptr</a></code> Never throws. </p>
</li>
</ol></div>
</div>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2005-2012 Ion Gaztanaga<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="to_raw_pointer_idp56801600.html"><img src="../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../boost_interprocess_reference.html#header.boost.interprocess.smart_ptr.scoped_ptr_hpp"><img src="../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="swap_idp56820848.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
